# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User

import sys

sys.path.append('./utils')
sys.path.append('../utils')

from utils import storage



# Create your models here.

# 个人博客
class UserInfo(models.Model):
    userid = models.CharField(max_length=64, null=True)
    username = models.CharField(max_length=64, null=True)
    pwd = models.CharField(max_length=64, null=True)


class ContactMessage(models.Model):
    contact_time = models.IntegerField(null=True)
    contact_name = models.CharField(max_length=64, null=True)
    contact_email = models.CharField(max_length=64, null=True)
    contact_body = models.CharField(max_length=64, null=True)


class Article(models.Model):
    article_uuid = models.CharField(max_length=64, null=True)
    article_title = models.CharField(max_length=64, null=True)
    article_author = models.CharField(max_length=64, null=True)
    article_time = models.CharField(max_length=64, null=True)
    article_content = models.CharField(max_length=10240, null=True)
    article_img = models.ImageField(upload_to='article_img/', default='article_img/1.jpg', storage=storage.ImageStorage())


class Comment(models.Model):
    article_uuid = models.CharField(max_length=64, null=True)
    comment_time = models.CharField(max_length=64, null=True)
    comment_name = models.CharField(max_length=64, null=True)
    comment_message = models.CharField(max_length=256, null=True)


# 图书借阅
class Books(models.Model):
    book_uuid = models.CharField(max_length=64, null=True)
    book_name = models.CharField(max_length=64, null=True)
    author = models.CharField(max_length=64, null=True)
    publisher = models.CharField(max_length=64, null=True)
    publish_date = models.CharField(max_length=64, null=True)
    price = models.IntegerField(null=True, default=0)


class BookComment(models.Model):
    book_uuid = models.CharField(max_length=64, null=True)
    comment_user = models.CharField(max_length=64, null=True)
    comment_content = models.CharField(max_length=128, null=True)
    comment_time = models.CharField(max_length=64, null=True)


# session
class User(models.Model):
    name = models.CharField(max_length=20, null=False)
    email = models.EmailField()
    password = models.CharField(max_length=20, null=False)
    enabled = models.BooleanField(default=False)

    def __unicode__(self):
        return self.name


class Mood(models.Model):
    status = models.CharField(max_length=10, null=False)

    def __unicode__(self):
        return self.status


class Post(models.Model):
    mood = models.ForeignKey('Mood', on_delete=models.CASCADE)
    nickname = models.CharField(max_length=10, default='不愿意透露身份的人')
    message = models.TextField(null=False)
    del_pass = models.CharField(max_length=10)
    pub_time = models.DateTimeField(auto_now=True)
    enabled = models.BooleanField(default=False)

    def __unicode__(self):
        return self.message

